package gameEngine.agents.distrebution.representation;

import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class NormalRepresentation extends DistributionRepresentation{

	Logger log = Logger.getLogger(this.getClass());
	
	private 	double 	mean = 0;
	private 	double 	variance = 0;
	
	/**
	 * CTOR
	 */
	public NormalRepresentation(String name, double mean, double variance)
	{
		this.distributionName 	= name;
		this.mean 				= mean;
		this.variance			= variance;
	}

	/**
	 * CTOR
	 * Designed for Open XML procedure
	 */
	public NormalRepresentation(String name)
	{
		this.distributionName 	= name;
	}
	
	//methods
	public double getMean() {
		return mean;
	}

	public void setMean(double mean) {
		this.mean = mean;
	}

	public double getVariance() {
		return variance;
	}

	public void setVariance(double variance) {
		this.variance = variance;
	}
	
	
	@Override
	public void setExtraElement(Document doc, Element distribution) {
		
		//mean element 
		Element mean = doc.createElement("Mean");
		mean.appendChild(doc.createTextNode(Double.toString(this.mean)));
		
		//variance element 
		Element variance = doc.createElement("Variance");
		variance.appendChild(doc.createTextNode(Double.toString(this.variance)));
		
		
		distribution.appendChild(mean);
		distribution.appendChild(variance);
	}

	
	
	/**
	 * Set this distribution data from XML 
	 */
	public void openExtraDistributionData(Document doc, Element distElement)
	{
		NodeList list = distElement.getElementsByTagName("Mean");
		Element meanElement = (Element)list.item(0); 
		//take the text value of mean
		String 	meanStr = getTagValue(meanElement.getNodeName(), distElement);
		double  mean = Double.parseDouble(meanStr);
		log.debug("Mean value in the XML is " + mean);
		this.mean = mean;	
		
		list = distElement.getElementsByTagName("Variance");
		Element varianceElement = (Element)list.item(0); 
		//take the text value of variance
		String 	varianceStr = getTagValue(varianceElement.getNodeName(), distElement);
		double  variance = Double.parseDouble(varianceStr);
		log.debug("Variance value in the XML is " + variance);
		this.variance = variance;
	}
	
	
}
